﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Appcode;

public partial class Cart : WebPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadImgData();
            cartStep1.Visible = true;
            cartStep2.Visible = false;
            cartStep3.Visible = false;
            cartComplete.Visible = false;           
        }
    }

    public void loadImgData() {
        List<Images> listCart = Session.GetShopingCart();

        GridView1.DataSource = listCart;

        GridView1.DataBind();
    }

    

    public String getTotalPriceByID(String _id) {
        List<Images> listCart = Session.GetShopingCart();
        float totalPrice=0;

        for (int i = 0; i < listCart.Count; i++)
        {
            if (listCart[i].ImageID==Convert.ToInt32(_id))
            {
                totalPrice = listCart[i].ImgQuantity * listCart[i].UnitPrice;
                break;
            }
        }

        return totalPrice.ToString();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        loadImgData();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        

    }
    protected void btnNext1_Click(object sender, EventArgs e)
    {
        cartStep1.Visible = false;
        cartStep2.Visible = true;
        cartStep3.Visible = false;
        cartComplete.Visible = false;
    }
    protected void btnNext2_Click(object sender, EventArgs e)
    {
        cartStep1.Visible = false;
        cartStep2.Visible = false;
        cartStep3.Visible = true;
        cartComplete.Visible = false;
    }
    protected void btnStep3_Click(object sender, EventArgs e)
    {
        cartStep1.Visible = false;
        cartStep2.Visible = false;
        cartStep3.Visible = false;
        cartComplete.Visible = true;
    }
    protected void btnBackAlbum_Click(object sender, EventArgs e)
    {
        Response.Redirect("AlbumManager.aspx");
    }
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        //GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        //int index = gvRow.RowIndex;
        //TextBox txtQuan = (TextBox)GridView1.Rows[index].FindControl("txtQuantity");
        //int imgID = Convert.ToInt32(GridView1.DataKeys[index].Values[0].ToString());
        //int quan = Convert.ToInt32(txtQuan.Text);

        //List<Image> listCart = Session.GetShopingCart();

        //for (int i = 0; i < listCart.Count; i++)
        //{
        //    if (listCart[i].ImageID==imgID && quan > 0)
        //    {
        //        listCart[i].ImgQuantity = quan;
        //        break;
        //    }
        //}

        //Session.SetShopingCart(listCart);

        
    }
    protected void btnremove_Click(object sender, EventArgs e)
    {

    }
}